package com.itcast.service;

import com.alibaba.dubbo.config.annotation.Service;

import com.itcast.dao.RelativeDao;
import com.itcast.health.entity.Result;
import com.itcast.health.pojo.Member;
import com.itcast.health.pojo.RelativeInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author: libin
 * @date: 2019/12/3 14:49
 * @version: 1.0
 * @describe:
 */

@Service(interfaceClass = RelativeService.class)
@Transactional
public class RelativeServiceImpl implements RelativeService {

    @Autowired
    RelativeDao relativeDao;

    /**
     * 添加联系人
     * @param id
     * @param relativeInfoVo
     * @return
     */
    @Override
    public Result add(Integer id, RelativeInfoVo relativeInfoVo) {
        //根据联系人的姓名和身份证号查询是否有会员
        Member member = relativeDao.findByNameAndIdCard(relativeInfoVo);
        if (null!=member) {
            return new Result(false,"请不要重复添加联系人");
        }
        //没有就添加联系人(id,relativeInfoVo)
        relativeDao.add(id,relativeInfoVo);
        return new Result(true,"添加联系人成功");
    }

    /**
     * 查询所有联系人
     * @param id
     * @return
     */
    @Override
    public List<Member> findAllRelative(Integer id) {
        //根据id查询所有联系人，包括自己
        List<Member> members = relativeDao.findAllRelative(id);

        return members;
    }

    /**
     * 根据id查询联系人
     * @param id
     * @return
     */
    @Override
    public Member findRelativeById(Integer id) {
        Member member = relativeDao.findRelativeById(id);
        return member;
    }
}
